import React, { useState } from 'react'
import { SearchBar } from "antd-mobile/2x"
import fd from '../../utils/fd'
import api from '../../api/index'
import { useHistory } from "react-router-dom"
export default function Search() {
    const { push } = useHistory();
    const [list, setList] = useState([])
    const search = (val) => {

        fd(() => {
            api.searchCommunity({
                name: val,
                id: localStorage.getItem("id")
            }).then(res => {
                console.log(res);
                setList([...res.body])
            })
        })
    }
    return (
        <div style={{ padding: "10px 20px" }}>
            <SearchBar placeholder='请输入内容' onChange={(val) => search(val)} />
            <div style={{ padding: "10px 0", lineHeight: "30px", color: "#999" }}>
                {
                    list.length > 0 && list.map(item => {
                        return <p onClick={() => push({
                            pathname: "/housesAdd",
                            state: {
                                name: item.communityName,
                                community: item.community
                            }
                        })}>{item.communityName}</p>
                    })
                }
            </div>
        </div>
    )
}
